package com.free.compilation.controller;

import com.free.common.core.web.controller.BaseController;
import com.free.common.core.web.domain.AjaxResult;
import com.free.common.core.web.domain.R;
import com.free.common.core.web.page.TableDataInfo;
import com.free.common.log.annotation.Log;
import com.free.common.log.enums.BusinessType;
import com.free.compilation.domain.CompilationClassify;
import com.free.compilation.domain.ZoneCompilation;
import com.free.compilation.service.ZoneCompilationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 合集Controller
 *
 * @author free
 * @date 2023-07-25
 */
@RestController
@RequestMapping("/compilation")
@Slf4j
public class ZoneCompilationController extends BaseController {
    @Autowired
    private ZoneCompilationService zoneCompilationService;

    /**
     * 查询合集列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ZoneCompilation zoneCompilation) {
        startPage();
        List<ZoneCompilation> list = zoneCompilationService.selectZoneCompilationList(zoneCompilation);
        return getDataTable(list);
    }

    /**
     * 查询合集列表
     */
    @GetMapping("/compilationClassifyAll")
    public R compilationClassifyAll() {
        List<CompilationClassify>  list = zoneCompilationService.compilationClassifyAll();
        return R.ok(list);
    }

    /**
     * 获取合集详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(zoneCompilationService.selectZoneCompilationById(id));
    }

    /**
     * 新增合集
     */
    @Log(title = "合集", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZoneCompilation zoneCompilation) {
        return toAjax(zoneCompilationService.insertZoneCompilation(zoneCompilation));
    }

    /**
     * 修改合集
     */
    @Log(title = "合集", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZoneCompilation zoneCompilation) {
        return success(zoneCompilationService.updateZoneCompilation(zoneCompilation));
    }

    /**
     * 删除合集
     */
    @Log(title = "合集", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long ids) {
        log.info("ids-->{}",ids);
        return toAjax(zoneCompilationService.deleteZoneCompilationByIds(ids));
    }
    @Log(title = "合集", businessType = BusinessType.DELETE)
    @DeleteMapping("/listStep")
    public AjaxResult listStep(@PathVariable Long id) {
        return toAjax(zoneCompilationService.listStep(id));
    }
}
